<template>
	<div>
		<el-form :inline="true" :model="studentSearchForm">
			<!-- 添加按钮 -->
			<el-form-item><el-button icon="el-icon-circle-plus" @click="insertStudent" circle></el-button></el-form-item>
			<!-- 下面是查询项 -->
			<!-- 学生的名字 -->
			<el-form-item label="名字:">
				<el-input v-model="studentSearchForm.sname" placeholder="学生姓名...">
				</el-input>
				</el-form-item>
			<!-- 性别 -->
			<el-form-item label="性别:">
				<el-select v-model="studentSearchForm.ssex">
					<el-option label="男" value="男"></el-option>
					<el-option label="女" value="女"></el-option>
				</el-select>
			</el-form-item>
			<!-- 班级 -->
			<el-form-item label="班级:">
				<el-select v-model="studentSearchForm.sclassid">
					<el-option :label="item.cname" :value="item.cid" @change="onSelectChange" v-for="item in classesInfo" :key="item.cid"></el-option>
				</el-select>
			</el-form-item>

			<el-form-item>
				<span class="demonstration">按时间</span>
				<el-date-picker
					v-model="empDate"
					value-format="yyyy-MM-dd hh:mm:ss"
					type="daterange"
					range-separator="至"
					start-placeholder="开始日期"
					end-placeholder="结束日期"
				></el-date-picker>
			</el-form-item>
			<el-form-item><el-button @click="onSearch">搜 索</el-button></el-form-item>
			<el-form-item><el-button @click="onCanel">取 消</el-button></el-form-item>
		</el-form>
	</div>
</template>

<script>
export default {
	props:['classesInfo'],
	data() {
		return {
			studentSearchForm : this.$parent.studentSearchForm,
			empDate : this.$parent.empDate
		};
	},
	methods:{
		/* 点击新增按钮 */
		insertStudent() {
			this.$parent.$refs.dialog.dialogFormVisible = true;
			this.$parent.fromTitle = '新增学生'; //给打开的dialog设置title
			this.$parent.form = {};
			this.$parent.isUpdate = false; // 点前点击的是添加按钮
		},
		onSelectChange(val1) {
			/* 调用父组件的方法 */
			this.$parent.onSelectChange(val1);
		},
		/* 多条件查询 */
		onSearch() {
			console.log(this.empDate)
			console.log("parent")
			console.log(this.$parent.empDate)
			if (this.$parent.empDate != null) {
				this.$parent.studentSearchForm.starTime = this.empDate.toString().split(',')[0];
				this.$parent.studentSearchForm.endTime = this.empDate.toString().split(',')[1];
			}
			this.$parent.search_studentInfo();
		},
		onCanel() {
			/* 清空临时暂存时间值 */
			this.$parent.studentSearchForm.starTime = null;
			this.$parent.studentSearchForm.endTime = null;
			this.$parent.studentSearchForm.ssex = '';
			this.$parent.studentSearchForm.sname = '';
			this.$parent.studentSearchForm.sclassid = '';
			this.$parent.empDate = null;
			this.onSearch();
		}
	}
};
</script>

<style scoped></style>
